<?php
class BZ_Config extends CI_Config
{
    public $store_id; //站点store_id，很重要。
    public $www_base_url        = 'http://www.zxkj918.com/';
    public $images_url          = 'http://img.zxkj918.com/';
    public $wap_base_url        = 'http://wap.zxkj918.com/';
    public $gongying_url        = 'http://gongying.zxkj918.com/';
    public $login_url           = 'http://login.zxkj918.com/';

    /**
     * 构造函数初始化https解决
     */
    public function __construct()
    {
        $this->config =& get_config();
        $httpType  = 'http';
        if ($this->config['base_url'] == '') {
            if (isset($_SERVER['HTTP_HOST'])) {
                $base_url  = $httpType.'://'. $_SERVER['HTTP_HOST'];
                $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
            } else {
                $base_url = $httpType.'://localhost/';
            }
            $this->set_item('base_url', $base_url);
        }
        //配置域名
        $this->www_base_url = $httpType.'://www'.strstr($_SERVER['HTTP_HOST'], '.').'/';
        $this->gongying_url = $httpType.'://gongying'.strstr($_SERVER['HTTP_HOST'], '.').'/';
    }

    /**
     * 图片上传路径
     * @param string $dirname
     * @param string $imageName
     * @return string
     */
    public function upload_image_path($imageName = '', $dirname = 'uploads')
    {
        if (!empty($imageName)) {
            return FCPATH.'/'.$dirname.'/'.$imageName;
        }
        return FCPATH.'/'.$dirname.'/';
    }

    /**
     * 图片显示路径
     * @param string $imageName
     * @param string $size
     * @param string $dirname
     * @param bool $default
     * @return string
     */
    public function show_image_url($imageName = '', $size = '', $dirname = 'uploads', $default = false)
    {
        if (empty($imageName)) {
            return $default == false ? '/skins/common/images/nophoto.jpg' : $imageName;
        }
        if (strpos($imageName, ',') !== false) {
            $imageName = strstr($imageName, ',', true);
        }
        $dataSize = ['100-100', '200-200', '300-300', '400-400', '640-640', '640-220'];
        if (strpos($imageName, 'http') === false) {
            if (in_array($size, $dataSize)) {
                $src = $this->images_url.$dirname.$imageName.'?x-oss-process=style/'.$size;
            } else {
                $src = $this->images_url.$dirname.$imageName;
            }
        } else {
            $src = $imageName;
        }
        return $src;
    }

    /**
     * Site URL
     * Returns base_url . index_page [. uri_string]
     *
     * @access	public
     * @param	string	the URI string
     * @return	string
     */
    function site_url($uri = '')
    {
        if ($uri == '')
        {
            return $this->slash_item('base_url').$this->item('index_page').$this->store_id;
        }

        if ($this->item('enable_query_strings') == FALSE)
        {
            $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
            return $this->slash_item('base_url').$this->slash_item('index_page').$this->store_id.$this->_uri_string($uri).$suffix;
        }
        else
        {
            return $this->slash_item('base_url').$this->item('index_page').$this->store_id.'?'.$this->_uri_string($uri);
        }
    }
}